<?php


namespace App\Transformers\System;


use App\Models\SystemConfig;
use League\Fractal\TransformerAbstract;

class SystemSettingsTransformer extends TransformerAbstract
{
    public function transform(SystemConfig $systemconfig)
    {
        $arr = explode(' ',$systemconfig->parameter);
        $parameter = [];
        foreach ($arr as $v){
            $vrr = explode('=>',$v);
            foreach ($vrr as $v2){
                if (is_numeric($v2)){
                    $arrr['value'] = $v2;
                }else{
                    $arrr['label'] = $v2;
                }
            }
            $parameter[] = $arrr;
        }

        return [
            'id' => $systemconfig->id,
            'menu_name' => $systemconfig->menu_name ?? '',
            'category_id' => $systemconfig->category_id ?? '',
            'category_name' => $systemconfig->category_name ?? '',
            'type' => $systemconfig->type ?? '',
            'input_type' => $systemconfig->input_type ?? '',
            'parameter' => $systemconfig->parameter ? $parameter : '',
            'upload_type' => $systemconfig->upload_type ?? '',
            'required' => $systemconfig->required ?? '',
            'width' => $systemconfig->width ?? '',
            'height' => $systemconfig->height ?? '',
            'value' => $systemconfig->value ?? '',
            'info' => $systemconfig->info ?? '',
            'desc' => $systemconfig->desc ?? '',
        ];
    }
}
